<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登录日志</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css"/>
    <style>
        .layui-table .layui-input {
            text-align: center;
        }

        .editRowExt xm-select {
            min-height: 40px !important;
            line-height: 40px !important;
        }

        .editRowExt .layui-form-switch {
            top: 10px !important;
        }

        .query {
            display: none;
            padding: 0px 5px;
        }
    </style>
</head>
<body class="pear-container">
<div class="query">
    <form class="layui-form" action="">
        <div class="layui-row layui-col-space10">
            <div class="layui-col-md12">
                <div class="layui-card" style="margin-top: 10px;">
                    <div class="layui-card-header">账号</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <input type="text" name="userId" placeholder="账号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-card" style="margin-top: 10px;">
                    <div class="layui-card-header">姓名</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <input type="text" name="userName" placeholder="姓名" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-card" style="margin-top: 10px;">
                    <div class="layui-card-body layui-row layui-col-space10">
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="query">
                            <i class="layui-icon layui-icon-search"></i>
                            查询
                        </button>
                        <button type="reset" class="pear-btn pear-btn-md">
                            <i class="layui-icon layui-icon-refresh"></i>
                            重置
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="layui-card">
    <div class="layui-card-body userList">
        <table id="table_list" lay-filter="table_list"></table>
    </div>
</div>

<script type="text/html" id="user-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="query">
        <i class="icon pear-icon pear-icon-search"></i>
        查询
    </button>
</script>


<script type="text/html" id="list-loginTime">
    {{layui.util.toDateString(d.loginTime, 'yyyy-MM-dd HH:mm:ss')}}
</script>
<script src="../../../config/apiUrl.js"></script>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
    layui.use(['newTable', 'form', 'jquery', 'common', 'http', 'tableEdit', 'toast', 'popup', 'drawer'], function () {
        let table = layui.newTable;
        let form = layui.form;
        let $ = layui.jquery;
        var http = layui.http;
        var drawer = layui.drawer;

        let cols = [
            [{
                type: 'numbers', fixed: "left",width:80
            },
                {
                    title: '账号',
                    field: 'userid',
                    align: 'center',
                },
                {
                    title: '姓名',
                    field: 'username',
                    align: 'center'
                },
                {
                    title: '登录时间',
                    field: 'loginTime',
                    align: 'center',
                    templet: '#list-loginTime'
                },
                {
                    title: '浏览器',
                    field: 'browser',
                    align: 'center'
                },
                {
                    title: '设备',
                    field: 'device',
                    align: 'center'
                }
            ]
        ]

        var tableObj = table.render({
            contentType: "application/x-www-form-urlencoded",
            height: 'full-80',
            elem: '#table_list',
            url: apiUrlConfig.user.loginLogList,
            page: true,
            cols: cols,
            skin: 'line',
            method: 'post',
            toolbar: '#user-toolbar',
            limit: 10,
            limits: [10],
            request: {
                pageName: 'page' //页码的参数名称，默认：page
                , limitName: 'limit' //每页数据量的参数名，默认：limit
            },
            headers: {
                "authorization": http.ajax.getToken()
            },
            defaultToolbar: ['filter', 'print', 'exports']
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.status, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records //解析数据列表
                };
            }
            , response: {
                statusCode: 200 //规定成功的状态码，默认：0
            }
        });

        table.on('toolbar(table_list)', function (obj) {
            if (obj.event === 'query') {
                drawer.open({
                    direction: "right",
                    dom: ".query",
                    distance: "30%"
                });
            }
        });

        form.on('submit(query)', function (data) {
            tableObj = table.reload("table_list", {
                where: data.field
            }, true)
            return false;
        });

        window.refresh = function (param) {
            table.reload('table_list');
        }
    })
</script>
</body>
</html>
